#define _CRT_SECURE_NO_WARNINGS 1

#include <string>
using namespace std;

class Solution {
public:
    string convert(string s, int numRows) {
        if (numRows == 1) return s;
        string ret;
        int d = 2 * numRows - 2;
        for (int i = 0; i < numRows; ++i)
        {
            for (int j = i, k = d - j; j < s.size(); j += d, k += d)
            {
                ret += s[j];
                if (i != 0 && i != numRows - 1 && k < s.size()) ret += s[k];
            }
        }
        return ret;
    }
};